<#-- 导入模版定义文件-->
<#include "../template/template_editPage.ftl">
<@edit title="管理员操作">
	<#if (userId)??>
		<#assign isEdit = true />
	<#else>
		<#assign isAdd = true />
	</#if>
	<body class="input">
	<script type="text/javascript">
	$().ready( function() {
	
		var $validateErrorContainer = $("#validateErrorContainer");
		var $validateErrorLabelContainer = $("#validateErrorContainer ul");
		var $validateForm = $("#validateForm");
		var $tab = $("#tab");
	
		// Tab效果
		$tab.tabs(".tabContent", {
			tabs: "input"
		});
		
		// 表单验证
		$validateForm.validate({
			errorContainer: $validateErrorContainer,
			errorLabelContainer: $validateErrorLabelContainer,
			wrapper: "li",
			errorClass: "validateError",
			ignoreTitle: true,
			rules: {
			    "operator.userName": {
					required: true,
					minlength: 1,
					maxlength: 20
				},
				"operator.password": {
					required: true,
					minlength: 4,
					maxlength: 20
				},
				"repwd": {
					required: true,
					equalTo: "#password"
				},
				"operator.email": {
					email: true
				},
				"operator.mobile": {
					mobile: true
				}
				,
				"operator.roleId": {
					required: true
				}
			},
			messages: {
				"operator.userName": {
					required: "请填写用户姓名",
					minlength: "用户姓名必须大于等于1",
					maxlength: "用户姓名必须小于等于20"
				},
				"operator.password": {
					required: "请填写密码",
					minlength: "密码必须大于等于4",
					maxlength: "密码必须小于等于20"
				},
				"repwd": {
					required: "请填写重复密码",
					equalTo: "两次密码输入不一致"
				},
				"operator.email": {
					email: "E-mail格式不正确"
				},
				"operator.tel": {
					mobile: "手机格式不正确"
				},
				"operator.roleId": {
					required: "请选择用户角色"
				}				
			},
			submitHandler: function(form) {
				$(form).find(":submit").attr("disabled", true);
				form.submit();
			}
		});
		<#if actionErrors??&&(actionErrors?size > 0)>
			$.dialog({type: "warn", content: "<#list errorMessages as list>${list}<br></#list>", modal: true, autoCloseTime: 3000});
		</#if>
	});
	</script>
		<div class="body">
			<div class="inputBar">
				<h1><span class="icon">&nbsp;</span><#if isAdd??>添加管理员<#else>编辑管理员</#if></h1>
			</div>
			<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
				<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
				<ul></ul>
			</div>			
			<form id="validateForm" class="validate" method="post" action="<#if isAdd??>${web_base}/system/admin!save.htm<#else>${web_base}/system/admin!edit.htm</#if>">
			<table class="inputTable tabContent">
			<tr>

				<th>用户账号:</th>
				<td>
					<#if isAdd??>
					<input type="text" name="operator.userId" class="formText {required: true, username: true, remote:'admin!checkUser.htm', minlength: 2, maxlength: 20, messages: {remote: '用户名已存在,请重新输入!'}}" 
				    value="">
				    <label class="requireField">*</label>
				    <#else>
				    ${(operator.userId)!}<input type="hidden" name="operator.userId" value="${(operator.userId)!}" />
				    </#if>
				  </td>
			</tr>
			<tr>
				<th>用户姓名:</th>
				<td><input type="text" name="operator.userName" class="formText"  value="${(operator.userName)!}"></td>
			</tr>
			<#if isAdd??>
			<tr>
				<th>用户密码:</th>
				<td><input type="password" name="operator.password" id="password" class="formText" value=""><label class="requireField">*</label></td>
			</tr>
			<tr>
				<th>请再次输入密码:</th><td><input type="password" name="repwd" class="formText" value=""><label class="requireField">*</label></td>
			</tr>
			</#if>
			<tr>
				<th>用户角色:</th>
				<td>
					<select name="operator.roleId">
						<#if roles??>
							<#list roles as role>
							<option value="${(role.roleId)!}" <#if isEdit??><#if operator.roleId=="${(role.roleId)!}" >selected="selected"</#if></#if>>${(role.roleName)!}</option>
							</#list>
						</#if>
					</select>
					<label class="requireField">*</label>
				</td>
				
			</tr>
			<tr>
				<th>手机号码:</th>
				<td><input type="text" id="tel"  class="formText" name="operator.mobile" value="${(operator.mobile)!}" ></td>
			</tr>
			<tr>
				<th>邮箱:</th>
				<td><input type="text" name="operator.email" class="formText"  value="${(operator.email)!}"></td>
			</tr>
			
			</table>
			<div class="buttonArea">
				<input type="submit" class="formButton" value="<#if isAdd??>注册<#else>修改</#if>" hidefocus="true" />&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="取  消" hidefocus="true" />
			</div>
            </form>
		</div>
	</body>

</@edit>